home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 44 / Amiga Format CD44 (1999-08-26)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-10].iso / -in_the_mag- / basics / amos / keyfilemaker.lha / Keyfile / Keyread.AMOS / Keyread.amosSourceCode
AMOS Source Code  |  1999-06-19  |  1KB  |  70 lines

  1. ' Keyfile reader v1.0 [990619] 
  2. ' By Nikolaos Theologou (wizbone@hem.passagen.se)  
  3.  
  4. Screen Open 0,640,200,4,Hires
  5. Curs Off : Cls 0 : Paper 0 : Flash 3,"(fff,5)(000,5)"
  6. Print "Keyfile reader"
  7. Print "--------------"
  8.  
  9. ' Read the file
  10.  
  11. F$=Fsel$("*.key","Program.key","Select the keyfile")
  12.  
  13. Trap Open In 1,F$
  14.  If Errtrap<>0 Then Print "No keyfile was found." : End 
  15.  
  16.  CHEKSUM$=Input$(1,1)
  17.  ID$=Input$(1,1)
  18.  IDCHK$=Input$(1,1)
  19.  Input #1,NAME$
  20. Close 1
  21.  
  22. ' Get variabels  
  23.  
  24. NAMELEN=Len(NAME$)
  25. REALSUM=Asc(CHEKSUM$)
  26. ID=Asc(ID$)
  27. IDCHK=Asc(IDCHK$)
  28.  
  29. ' Decrypt it 
  30.  
  31. For I=1 To NAMELEN
  32.  TEMP$=TEMP$+Chr$(Asc(Right$(Left$(NAME$,I),1))-(I*2))
  33. Next : NAME$=TEMP$ : TEMP$=""
  34.  
  35. ' Mirror it
  36.  
  37. For I=1 To NAMELEN
  38.  TEMP$=TEMP$+Chr$(Asc(Right$(Left$(NAME$,NAMELEN+1-I),1)))
  39. Next : NAME$=TEMP$ : TEMP$=""
  40.  
  41. ' Get the checksum of the name 
  42.  
  43. For I=1 To NAMELEN
  44.  Add CHEKSUM,Asc(Right$(Left$(NAME$,I),1))
  45. Next 
  46.  
  47. ' Minimize the checksum  
  48.  
  49. While CHEKSUM>255 : CHEKSUM=CHEKSUM-255 : Wend 
  50. ID=ID-CHEKSUM
  51. IDCHK=IDCHK-20
  52.  
  53. ' Check if the keyfile is valid
  54.  
  55. If REALSUM=CHEKSUM and ID=IDCHK Then OK=True
  56. If REALSUM<>CHEKSUM and ID<>IDCHK Then OK=False
  57.  
  58. If OK=True Then Print "The keyfile is a valid Program.key"
  59. If OK=False Then Print "Warning! The keyfile is not a valid Program.key"
  60.  
  61. Print : Print "User : ";NAME$
  62. Print "ID   :";ID
  63. Print 
  64. Print "Checksum          :";CHEKSUM
  65. Print "Expected Checksum :";REALSUM
  66. Print 
  67. Print "ID Checksum          :";ID
  68. Print "Expected ID Checksum :";IDCHK
  69.  
  70. End